import { Column, Entity, PrimaryGeneratedColumn, Unique } from 'typeorm'

@Entity('user_checkin')
@Unique(['userId', 'checkin_time']) // 核心约束：同一用户同一天只能有一条签到记录
export class UserCheckinEntity {
  @PrimaryGeneratedColumn()
  id: number

  @Column({ type: 'int' })
  userId: number

  @Column({ type: 'int', default: Math.floor(Date.now() / 1000) })
  create_time: number

  @Column({ type: 'int', default: Math.floor(Date.now() / 1000) })
  checkin_time: number

  @Column({ type: 'int', default: 10, comment: '本次签到获得的饭币奖励' })
  rewardCoin: number

  @Column({ type: 'int', default: 0, comment: '连续签到额外奖励' })
  streakReward: number

  @Column({ type: 'int', default: 1, comment: '连续签到天数' })
  streakCount: number

  @Column({ type: 'int', comment: '所属月份', nullable: false })
  checkinMonth: number

  @Column({
    type: 'varchar',
    length: 255,
    default: '',
    comment: '当月签到日期列表'
  })
  checkinDays: string

  @Column({
    type: 'int',
    default: 0,
    comment: '用户签到累计获得的总积分'
  })
  totalCheckinReward: number
}